import doMigrate from './models/migrate';

import generateModels from './models/generateModels';

async function main() {
  const port = process.env['PORT'] || 8080;
  const host = process.env['HOST'] || '';

  if (__DEV__) {
    await doMigrate();
    await generateModels();
  }

  await new Promise((res, rej) => {
    const server = require('./app').listen(port, host, res);
    server.on('error', rej);
  });
  console.log('Ready');
}

main()
  .catch(err => {
    setImmediate(() => {
      throw err;
    });
  });
